package com.kitty.game.fight.pet;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.common.utils.Pair;
import com.kitty.game.utils.StatusConst;

import java.util.Random;

/**
 * 神龙罩
 * 对己方使用成功后，可以使被施法成员吸收对方的物理攻击。技能等级越高，吸收次数及可抵御的伤害越多
 */
public class ShenLongZhaoProcessor extends PetSkillProcessor {

    @Override
    public void trigger(Fight fight, FightObject effector, FightObject target, int skillLevel, Object... args) {
        int status = bindingStatus();
        int round = skillLevel / 20;
        round = Math.max(round, 2);
        int resist = new Double(1600 + new Random().nextInt(200) * skillLevel).intValue();
        target.setStatus(status, round);
        target.setStatusScore(status, resist);
    }

    @Override
    public Pair<Boolean, Integer> effect(Fight fight, FightObject effector, FightObject target, Object... args) {
        int hurt = (int) args[0];
        int status = bindingStatus();
        int round = target.getStatusValue(status);
        if (round >= 1) {
            int resist = target.getStatusScore(status);
            if (hurt > resist) {
                hurt = hurt - resist;
                target.setStatus(status, 0);
            } else {
                resist = resist - hurt;
                target.setStatusScore(status, resist);
                hurt = 0;
            }
            target.setStatus(status, round -1);
            if (target.getStatusValue(status) <= 0) {
                SpringUtils.getFightMessageService().sendFightAction(fight, target);
            }
            return new Pair<>(Boolean.TRUE, hurt);
        }
        return new Pair<>(Boolean.FALSE, 0);
    }

    public int bindingStatus() {
        return StatusConst.STATUS_IMMUNE_PHY_DAMAGE;
    }
}
